home *** CD-ROM | disk | FTP | other *** search
- Path: uuneo.neosoft.com!usenet
- From: Wmatthew@lan-aces.com (W. Matthews)
- Newsgroups: comp.lang.c++
- Subject: Re: HELP! error(3328)"class template .. has already been defined" when using multiple files
- Date: 11 Mar 1996 16:03:25 GMT
- Organization: LAN-ACES, Inc.
- Message-ID: <4i1isd$b7i@uuneo.neosoft.com>
- References: <314366C8.2F1C@st-andrews.ac.uk>
- NNTP-Posting-Host: 198.65.178.8
- X-Newsreader: WinVN 0.92.5
-
- In article <314366C8.2F1C@st-andrews.ac.uk>, Peter Foldiak <Peter.Foldiak@st-andrews.ac.uk> says:
- >
- >I would like to ask for some help with the following problem.
- >(I tried to simplify the files as much as possible).
- >When I try to compile the files below on a SG Indy I get the
- >following error:
- >
- >----
- >% CC main.c list.c
- Have you tried:
- % CC list.c main.c
- >main.c:
- >"list.h", line 1: error(3328): class template "list" has already been
- >defined
- > template<class T> class list {
- > ^
- >1 error detected in the compilation of "main.c".
- >list.c:
- >%
- >----
- >
- >If I concatenate list.c and main.c into a file called listmain.c,
- >and compile with
- >% CC listmain.c
- >%
- >the error message disapprears! So I guess it has something to do
- >with the bits being in separate files.
- >Also, if the files contain no templates there is no error.
- >Could anyone please help? Any ideas?
- >Is there something special with including headrers when I use templates?
- >Thanks!
- >
- >Peter
- >-
- >
- >===========================================
- >The files that won't compile:
- >
- >list.h:
- >-------
- >template<class T> class list {
- > T x;
- > list *next;
- >public:
- > list<T>::list();
- >};
- >
- >list.c:
- >-------
- >#include <stdio.h>
- >#include "list.h"
- >template<class T> list<T>::list()
- >{
- > next = NULL;
- >}
- >
- >main.c:
- >-------
- >#include "list.h"
- >int main()
- >{
- > list<int> q;
- > return 0;
- >}
- >
- >
- >=======================================
- >This file compiles without error:
- >listmain.c:
- >-----------
- >#include <stdio.h>
- >#include "list.h"
- >
- >template<class T> list<T>::list()
- >{
- > next = NULL;
- >}
- >
- >int main()
- >{
- > list<int> q;
- > return 0;
- >}
- >
- >--
- >Peter Foldiak http://psych.st-and.ac.uk:8080/~pf2
- >Psychological Laboratory phone: +44 1334 462087
- >University of St Andrews fax: +44 1334 463042
- >St Andrews KY16 9JU, U.K. e-mail: Peter.Foldiak@st-and.ac.uk
-
- ______________________________________________
- |Wyatt Matthews: Tech Support Department |
- |WMATTHEW@LAN-ACES.COM -Internet- |
- |WMATTHEW.MHS@LAN-ACES -MHS- |
- |LAN-ACES Tech Support (713)890-9786 |
- |LAN-ACES BBS (713)890-9790 |
- |LAN-ACES Fax (713)890-9731 |
- |LAN-ACES Sales (713)890-9787 |
- ______________________________________________
-